package cn.jlonely.xyhx.app.controller;


import cn.jlonely.xyhx.app.service.AppVitoService;
import cn.jlonely.xyhx.pojo.Review;
import cn.jlonely.xyhx.pojo.vo.VitoVo;
import cn.jlonely.xyhx.utils.Result;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Slf4j
@RestController
@RequestMapping("/app")
public class AppVitoController {

    /**
     * 获取某个榜单的投票信息
     */
    @Autowired
    private AppVitoService appVitoService;
    @GetMapping("/getvitoInfo")
    public Result  getVitoInfo(@RequestParam("id")Integer id){
        List<Review> vitoInfo = appVitoService.getVitoInfo(id);
        return Result.success(vitoInfo);
    }
    /**
     * 投票
     */
    @PostMapping("/createVito")
    public Result createVito(@RequestBody VitoVo vitoVo){
        try {
            appVitoService.createVito(vitoVo);
            return Result.success();
        }catch (Exception e){
            return Result.error("您已经投票过了");
        }

    }

}
